using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GeoFramework.Examples
{
    public partial class StringParsingForm : Form
    {
        public StringParsingForm()
        {
            InitializeComponent();

            // Call the textbox events to make them display formatted values
            AngleTextBox_TextChanged(this, EventArgs.Empty);
            AzimuthTextBox_TextChanged(this, EventArgs.Empty);
            DistanceTextBox_TextChanged(this, EventArgs.Empty);
            SpeedTextBox_TextChanged(this, EventArgs.Empty);
            LatitudeTextBox_TextChanged(this, EventArgs.Empty);
            LongitudeTextBox_TextChanged(this, EventArgs.Empty);
            PositionTextBox_TextChanged(this, EventArgs.Empty);
        }

        private void AngleTextBox_TextChanged(object sender, System.EventArgs e)
        {
            try
            {
                // Convert the string into an angle object
                Angle Result = Angle.Parse(AngleTextBox.Text);
                // And format it  ("h" for hours, "m" for minutes, "s" for seconds)
                ParsedAngle.Text = Result.ToString(AngleFormat.Text);
            }
            catch
            {
                ParsedAngle.Text = "(Unknown)";
            }
        }

        private void AzimuthTextBox_TextChanged(object sender, System.EventArgs e)
        {
            try
            {
                // Convert the string into an angle object
                Azimuth Result = Azimuth.Parse(AzimuthTextBox.Text);
                // And format it  ("h" for hours, "m" for minutes, "s" for seconds, 
                // and "c" or "cc" for compass direction.
                ParsedAzimuth.Text = Result.ToString(AzimuthFormat.Text);
            }
            catch
            {
                ParsedAzimuth.Text = "(Unknown)";
            }
        }

        private void DistanceTextBox_TextChanged(object sender, System.EventArgs e)
        {
            try
            {
                // Convert the string into an angle object
                Distance Result = Distance.Parse(DistanceTextBox.Text);
                // And format it (v for "value", u for "units")
                ParsedDistance.Text = Result.ToString(DistanceFormat.Text);
            }
            catch
            {
                ParsedDistance.Text = "(Unknown)";
            }
        }

        private void SpeedTextBox_TextChanged(object sender, System.EventArgs e)
        {
            try
            {
                // Convert the string into an angle object
                Speed Result = Speed.Parse(SpeedTextBox.Text);
                // And format it (v for "value", u for "units")
                ParsedSpeed.Text = Result.ToString(SpeedFormat.Text);
            }
            catch
            {
                ParsedSpeed.Text = "(Unknown)";
            }
        }

        private void LatitudeTextBox_TextChanged(object sender, System.EventArgs e)
        {
            try
            {
                // Convert the string into an angle object
                Latitude Result = Latitude.Parse(LatitudeTextBox.Text);
                // And format it (v for "value", u for "units")
                ParsedLatitude.Text = Result.ToString(LatitudeFormat.Text);
            }
            catch
            {
                ParsedLatitude.Text = "(Unknown)";
            }
        }

        private void LongitudeTextBox_TextChanged(object sender, System.EventArgs e)
        {
            try
            {
                // Convert the string into an angle object
                Longitude Result = Longitude.Parse(LongitudeTextBox.Text);
                // And format it (v for "value", u for "units")
                ParsedLongitude.Text = Result.ToString(LongitudeFormat.Text);
            }
            catch
            {
                ParsedLongitude.Text = "(Unknown)";
            }
        }

        private void PositionTextBox_TextChanged(object sender, System.EventArgs e)
        {
            try
            {
                // Convert the string into an angle object
                Position Result = Position.Parse(PositionTextBox.Text);
                // And format it (v for "value", u for "units")
                ParsedPosition.Text = Result.ToString(PositionFormat.Text);
            }
            catch
            {
                ParsedPosition.Text = "(Unknown)";
            }
        }
    }
}